<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>


<div style="margin-top: 10px;margin-right: 40px">
    <form class="layui-form" action="javascript:;">
        <input type="text" name="lotteryDrawId" id="lotteryDrawId" hidden="hidden">
        <div class="layui-form-item">
            <label class="layui-form-label">奖品</label>
            <div class="layui-input-block">
                <input type="text" name="award" id="award" lay-verify="required" autocomplete="off" placeholder="请输入奖品"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">中奖概率</label>
            <div class="layui-input-block">
                <input type="text" name="odds" id="odds" lay-verify="required|number" autocomplete="off" placeholder="请输入中奖概率"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            </div>
        </div>
    </form>
</div>


<script src="/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , $ = layui.$;
        let data = parent.layui.$("#editlotteryDrawConfigHidden").val();
        data = $.parseJSON(data);
        $("#lotteryDrawId").val(data.id);
        $("#award").val(data.award);
        $("#odds").val(data.odds);


        form.render();


        //监听提交
        form.on('submit(demo1)', function (data) {
            data.field.id = data.field.lotteryDrawId;
            let json = JSON.stringify(data.field);
            let index = parent.layer.getFrameIndex(window.name);
            console.log(json);
            $.ajax({
                type: "POST",
                url: "lotteryDrawConfig/update",
                data: json,
                dataType: "json",
                contentType: 'application/json',
                success: function (msg) {
                    parent.layui.$("#editlotteryDrawConfigHidden").val("success");
                    parent.layer.close(index);
                },
                error: function (msg) {
                    parent.layui.$("#editlotteryDrawConfigHidden").val("error");
                    parent.layer.close(index);
                }
            });
        });

    });
</script>

</body>
</html>